package com.wukong.servlet;
/* author: 悟空非空也（B站/知乎/公众号） */


import com.wukong.util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class MyRegister  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     // post 请求的方式，使用此方法无效
        //   request.setCharacterEncoding("utf-8");
     //   response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();

        //接收用户名参数
        String username = request.getParameter("username");

        // 在页面上输出
        out.println("用户名为："+ username);
        // 在控制台输出
        System.out.println("用户名为："+ username );
        // 作业： 存入到数据库中
        // ？？？？？？
        JdbcUtil jdbcUtil = new JdbcUtil();
        /**
         * 1 连接数据库
         * 2  向数据库中插入请求参数
         *
         */

        // 接收密码参数
        String password = request.getParameter("password");
        out.println("密码为:" + password);
        System.out.println("密码为:" + password);

        // 接收邮箱参数
        String email = request.getParameter("email");
        out.println("邮箱为：" + email );
        System.out.println("邮箱为：" + email );

        // 接收爱好参数
        String[] hobbiesArray = request.getParameterValues("hobbies");
        for (String hobby: hobbiesArray) {
            out.println("爱好为：" +hobby);
            System.out.println("爱好为：" +hobby);
        }
    }
}
